package br.unipar.blog.view.action;

import java.io.Serializable;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

public abstract class AbstractUniparAction implements Serializable {
    
    protected void setMensagem(String mensagem) {
        FacesContext.getCurrentInstance()
                .addMessage(null, new FacesMessage(mensagem));
    }
    
    public static final String USUARIO_SESSION = "USUARIO_SESSION";
    
    public void putSession(String key, Object object) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map<String, Object> sessionMap = facesContext.
                getExternalContext().getSessionMap();
        sessionMap.put(key, object);
    }
    
    public Object getSession(String key) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map<String, Object> sessionMap = facesContext.
                getExternalContext().getSessionMap();
        return sessionMap.get(key);
    }
    
    public void clearSession() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map<String, Object> sessionMap = facesContext.
                getExternalContext().getSessionMap();
        sessionMap.clear();
    }
    
}
